976E - Well played - CodeForces Solution


greedy sortings *2100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cmath>
#include <algorithm>
#include <fstream>

#define endl "\n"
#define fi first
#define se second

#define pb push_back
#define mp(x, y) make_pair(x, y)
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

ll n, a, b, c, sum, s;
pii q[200000];

int main()
{
    cin >> n >> a >> b;
    c = b;

    for (int i = 0; i < n; i++) cin >> q[i].fi >> q[i].se;

    sort(q, q + n, [](pii a, pii b) { return a.fi - a.second > b.fi - b.se; });
    for (int i = 0; i < n; i++)
    {
        //cout << q[i].fi << " " << q[i].se << endl;
        if (b) sum += max(q[i].fi, q[i].se), b--;
        else sum += q[i].se;
    }

    b = c;
    if (b == 0) { cout << sum << endl; return 0; }
    s = sum;

    for (int i = 0; i < n; i++)
    {
        ll x = q[i].fi * pow(2, a);

        //cout << q[i].fi << " " << q[i].se << endl;
        //cout << (sum - max(q[c - 1].fi, q[c - 1].se)) + q[c - 1].se - q[i].se + x << endl;

        if (b)  s = max(s, (sum - max(q[i].fi, q[i].se)) + x), b--;
        else s = max(s, (sum - max(q[c - 1].fi, q[c - 1].se)) + q[c - 1].se - q[i].se + x);
    }

    cout << s << endl;

    return 0;
}


Comments

Submit
0 Comments
More Questions

721B - Passwords
1263D - Secret Passwords
1371B - Magical Calendar
1726E - Almost Perfect
1360C - Similar Pairs
900A - Find Extra One
1093D - Beautiful Graph
748A - Santa Claus and a Place in a Class
1511B - GCD Length
676B - Pyramid of Glasses
597A - Divisibility
1632A - ABC
1619D - New Year's Problem
242B - Big Segment
938A - Word Correction
159C - String Manipulation 10
258A - Little Elephant and Bits
1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier
1389C - Good String
1561A - Simply Strange Sort
1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble